module.exports = function (grunt) {
    grunt.initConfig({
        watch: {
            jade: {
                file: ['views/**'], // 监听目录
                options: {
                    livereload: true
                }
            },
            js: {
                file: ['public/js/**', 'models/**/*.js', 'schemas/**/*.js'],
                // tasks: ['jshint'], // 语法检查
                options: {
                    livereload: true  // 当文件改变会重启
                }
            }
        },
        jshint: {
          options: {
              jshintrc: '.jshintrc',
              ignores: ['public/libs/**/*.js']
          },
          all: ['public/js/*.js', 'test/**/*.js', 'app/**/*.js'] // 目录
        },
        less: {
          development: {
              options: {
                  compress: true,
                  yuicompress: true, // 压缩方式
                  optimization: 2
              },
              files: {
                  'public/build/index.css': 'public/less/index.css'
              }
          }
        },
        // uglify: {
        //     development: { // 开发文件
        //         files: {
        //             'public/build/admin.min.js': 'public/js/admin.js',
        //             'public/build/detail.min.js': [ // 多个文件压缩成一个文件
        //                 'public/js/detail.js'
        //             ]
        //         }
        //     }
        // },
        nodemon: {
            dev: {
                options: {
                    file: 'app.js', // 入口文件
                    agrs: [],
                    ignoredFiles: ['README.md', 'node_modules/**', '.DS_Store'],
                    watchedExtensions: ['js'],
                    watchedFolders: ['./'], // 当前根目录
                    // watchedFolders: ['app', 'config'],
                    debug: true,
                    delayTime: 1, // 如果有大批量需要编译的时候，就等待
                    env: {
                        PORT: 3000
                    },
                    cwd: __dirname
                }
            }
        },
        // 配置任务
        mochaTest: {
            options: {
                reporter: 'spec'
            },
            src: ['test/**/*.js']
        },
        concurrent: {
            tasks: ['nodemon', 'watch', 'less', 'uglify'],
            // tasks: ['nodemon', 'watch', 'less', 'uglify', 'jshint'],
            options: {
                logConcurrentOutput: true
            }
        }
    })
    grunt.loadNpmTasks('grunt-contrib-watch') // 只要有文件操作就会执行里面的注册任务
    grunt.loadNpmTasks('grunt-nodemon') // 实时监听 app.js
    grunt.loadNpmTasks('grunt-concurrent') // 慢任务插件 sass less 编译
    grunt.loadNpmTasks('grunt-mocha-test')
    grunt.loadNpmTasks('grunt-contrib-less')
    grunt.loadNpmTasks('grunt-contrib-uglify')
    grunt.loadNpmTasks('grunt-contrib-jshint')

    grunt.option('force',true)
    grunt.registerTask('default', ['concurrent'])
    grunt.registerTask('test', ['mochaTest'])
}